from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()


# def cut(value, arg):
#     """Removes all values of arg from the given string
#        example：{{ somevariable|cut:"0" }}
#     """
#     return value.replace(arg, '')
#
#
# def lower(value):
#     """Converts a string into all lowercase"""
#     return value.lower()
#
#
# register.filter('mycut', cut)
# register.filter('mylower', lower)


@register.filter(name='mycut')
def cut(value, arg):
    """Removes all values of arg from the given string
       example：{{ somevariable|cut:"0" }}
    """
    return value.replace(arg, '')

@register.filter(name='mylower')
def lower(value):
    """Converts a string into all lowercase"""
    return value.lower()


@register.filter()  # name不写时默认使用函数名， is_safe=True
@stringfilter
def str_and_int_cut(value, arg):
    """Removes all values of arg from the given string
       example：{{ somevariable|cut:"0" }}
    """
    return value.replace(arg, '')